package work20241219;

import java.io.File;

/**
 * @author zdl
 * @date 2024/12/19
 */
public class Demo3 {
    public static void main(String[] args) {
        //3.练习：统计一个文件夹的总大小  查官方API
        File file  = new File("D:/test");
        System.out.println(getFileLength(file));
    }
    public static long getFileLength(File file){
        long size = 0;
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()){
                size += file1.length();
            }else {
                getFileLength(file1);
                size += file1.length();
            }
        }
        return size;
    }
}
